#ifndef _MW_CONSOLE_POLLER_HPP_
#define _MW_CONSOLE_POLLER_HPP_

#include "config.hpp"
#include <boost/asio/io_service.hpp>
#include <string>
#include <streambuf>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>

namespace mw 
{

const size_t MAX_COMMAND_LENGTH = 512;

class ConsolePoller
{
public:
	ConsolePoller(boost::asio::io_service & io_service);

	virtual ~ConsolePoller();

	virtual void set_welcome(const std::string & welcome);

	virtual void set_prompt(const std::string & prompt);

	virtual void print_welcome() const;

	virtual void print_prompt() const;

	virtual void start_parse();

	virtual void stop_parse();
protected:
	virtual void run();

	virtual void process_line(const char * buffer) = 0;

	boost::asio::io_service & io_service_;
private:
	bool		quit_;
	std::string welcome_;
	std::string prompt_;
	char buffer_[MAX_COMMAND_LENGTH];
	boost::thread thread_;
};

} // end namespace mw

#endif // _MW_CONSOLE_POLLER_HPP_
